1
|
|
|
/*jslint |
2
|
|
|
regexp: true |
3
|
|
|
indent: 4 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
/*global |
7
|
|
|
$, google, |
8
|
|
|
Coordinates, Markers, TxtOverlay, |
9
|
|
|
id2alpha |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
function Line(themap, id, source, target) { |
13
|
|
|
'use strict'; |
14
|
|
|
|
15
|
|
|
this.m_map = themap; |
16
|
|
|
this.m_id = id; |
17
|
|
|
this.m_lineMapObject = null; |
18
|
|
|
this.m_source = -1; |
19
|
|
|
this.m_target = -1; |
20
|
|
|
this.m_distanceLabel = null; |
21
|
|
|
this.m_distance = -1; |
22
|
|
|
|
23
|
|
|
$('#dynLineDiv').append( |
24
|
|
|
"<div id=\"dynline" + id + "\">" + |
25
|
|
|
"<table style=\"width: 100%\">" + |
26
|
|
|
"<tr>" + |
27
|
|
|
"<td>" + |
28
|
|
|
"<select class=\"source my-small-select\" data-i18n=\"[title]sidebar.lines.source\" onchange=\"Lines.selectLineSource(" + id + ");\"><option value=\"-1\">?</option></select>" + |
29
|
|
|
" → " + |
30
|
|
|
"<select class=\"target my-small-select\" data-i18n=\"[title]sidebar.lines.destination\" onchange=\"Lines.selectLineTarget(" + id + ");\"><option value=\"-1\">?</option></select>" + |
31
|
|
|
"</td>" + |
32
|
|
|
"<td>" + |
33
|
|
|
"<button class=\"my-button btn btn-mini btn-danger\" style=\"float: right\" data-i18n=\"[title]sidebar.lines.delete_line\" type=\"button\" onClick=\"trackLine('delete'); Lines.deleteLine(" + id + ");\"><i class=\"fa fa-trash-o\"></i></button>" + |
34
|
|
|
"<div>" + |
35
|
|
|
"</div>" + |
36
|
|
|
"</td>" + |
37
|
|
|
"</tr>" + |
38
|
|
|
"<tr><td colspan=\"2\"><i class=\"fa fa-arrows-h\"></i> <span class=\"dist\">n/a</span> <i class=\"fa fa-compass\"></i> <span class=\"angle\">n/a</span></td></tr>" + |
39
|
|
|
"</table>" + |
40
|
|
|
"</div>" |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
this.updateLists(); |
44
|
|
|
this.setSource(source); |
45
|
|
|
this.setTarget(target); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
Line.prototype.m_map = null; |
50
|
|
|
Line.prototype.m_id = -1; |
51
|
|
|
Line.prototype.m_lineMapObject = null; |
52
|
|
|
Line.prototype.m_source = -1; |
53
|
|
|
Line.prototype.m_target = -1; |
54
|
|
|
Line.prototype.m_distanceLabel = null; |
55
|
|
|
Line.prototype.m_distance = -1; |
56
|
|
|
|
57
|
|
|
Line.prototype.getId = function () { |
58
|
|
|
'use strict'; |
59
|
|
|
|
60
|
|
|
return this.m_id; |
61
|
|
|
}; |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
Line.prototype.clearMapObject = function () { |
65
|
|
|
'use strict'; |
66
|
|
|
|
67
|
|
|
if (this.m_lineMapObject) { |
68
|
|
|
this.m_lineMapObject.setMap(null); |
69
|
|
|
this.m_lineMapObject = null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (this.m_distanceLabel) { |
73
|
|
|
this.m_distanceLabel.setMap(null); |
74
|
|
|
this.m_distanceLabel = null; |
75
|
|
|
} |
76
|
|
|
}; |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
Line.prototype.updateMapObject = function (pos1, pos2, center) { |
80
|
|
|
'use strict'; |
81
|
|
|
|
82
|
|
|
if (!this.m_lineMapObject) { |
83
|
|
|
this.m_lineMapObject = new google.maps.Polyline({ |
84
|
|
|
strokeColor: '#ff0000', |
85
|
|
|
strokeWeight: 2, |
86
|
|
|
strokeOpacity: 0.7, |
87
|
|
|
geodesic: true, |
88
|
|
|
icons: [{ |
89
|
|
|
icon: { |
90
|
|
|
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW |
91
|
|
|
}, |
92
|
|
|
repeat: '0' |
93
|
|
|
}] |
94
|
|
|
}); |
95
|
|
|
this.m_lineMapObject.setMap(this.m_map); |
96
|
|
|
this.m_distanceLabel = new TxtOverlay(center, "n/a", "mapDistanceLabel", this.m_map); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
var path = new google.maps.MVCArray(); |
100
|
|
|
path.push(pos1); |
101
|
|
|
path.push(pos2); |
102
|
|
|
this.m_lineMapObject.setPath(path); |
103
|
|
|
|
104
|
|
|
this.m_distanceLabel.setPos(center); |
105
|
|
|
}; |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
Line.prototype.getEndpointsString = function () { |
109
|
|
|
'use strict'; |
110
|
|
|
|
111
|
|
|
return id2alpha(this.m_source) + ":" + id2alpha(this.m_target); |
112
|
|
|
}; |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
Line.prototype.setSource = function (markerId) { |
116
|
|
|
'use strict'; |
117
|
|
|
|
118
|
|
|
if (markerId !== this.m_source) { |
119
|
|
|
this.m_source = markerId; |
120
|
|
|
this.update(); |
121
|
|
|
$("#dynline" + this.m_id + " .source > option[value=" + markerId + "]").attr("selected", "selected"); |
122
|
|
|
} |
123
|
|
|
}; |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
Line.prototype.setTarget = function (markerId) { |
127
|
|
|
'use strict'; |
128
|
|
|
|
129
|
|
|
if (markerId !== this.m_target) { |
130
|
|
|
this.m_target = markerId; |
131
|
|
|
this.update(); |
132
|
|
|
$("#dynline" + this.m_id + " .target > option[value=" + markerId + "]").attr("selected", "selected"); |
133
|
|
|
} |
134
|
|
|
}; |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
Line.prototype.update = function () { |
138
|
|
|
'use strict'; |
139
|
|
|
|
140
|
|
|
if (this.m_source === -1 || this.m_target === -1) { |
141
|
|
|
this.clearMapObject(); |
142
|
|
|
this.m_distance = -1; |
143
|
|
|
|
144
|
|
|
$("#dynline" + this.m_id + " .dist").html("n/a"); |
145
|
|
|
$("#dynline" + this.m_id + " .angle").html("n/a"); |
146
|
|
|
|
147
|
|
|
return; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
var pos1 = Markers.getById(this.m_source).getPosition(), |
151
|
|
|
pos2 = Markers.getById(this.m_target).getPosition(), |
152
|
|
|
dist_angle = Coordinates.dist_angle_geodesic(pos1, pos2), |
153
|
|
|
centerPos = Coordinates.projection_geodesic(pos1, dist_angle.angle, 0.5 * dist_angle.dist); |
154
|
|
|
|
155
|
|
|
this.updateMapObject(pos1, pos2, centerPos); |
156
|
|
|
this.m_distance = dist_angle.dist; |
157
|
|
|
|
158
|
|
|
if (dist_angle.dist <= 0) { |
159
|
|
|
this.m_distanceLabel.setText(""); |
160
|
|
|
$("#dynline" + this.m_id + " .dist").html("0m"); |
161
|
|
|
$("#dynline" + this.m_id + " .angle").html("n/a"); |
162
|
|
|
} else { |
163
|
|
|
this.m_distanceLabel.setText(dist_angle.dist.toFixed() + "m"); |
164
|
|
|
$("#dynline" + this.m_id + " .dist").html(dist_angle.dist.toFixed() + "m"); |
165
|
|
|
$("#dynline" + this.m_id + " .angle").html(dist_angle.angle.toFixed(1) + "°"); |
166
|
|
|
} |
167
|
|
|
}; |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
Line.prototype.updateMarkerMoved = function (markerId) { |
171
|
|
|
'use strict'; |
172
|
|
|
|
173
|
|
|
if (this.m_source === markerId || this.m_target === markerId) { |
174
|
|
|
this.update(); |
175
|
|
|
} |
176
|
|
|
}; |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
Line.prototype.updateMarkerRemoved = function (markerId) { |
180
|
|
|
'use strict'; |
181
|
|
|
|
182
|
|
|
if (this.m_source === markerId) { |
183
|
|
|
this.m_source = -1; |
184
|
|
|
this.clearMapObject(); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
if (this.m_target === markerId) { |
188
|
|
|
this.m_target = -1; |
189
|
|
|
this.clearMapObject(); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
this.updateLists(); |
193
|
|
|
}; |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
Line.prototype.updateMarkerAdded = function () { |
197
|
|
|
'use strict'; |
198
|
|
|
|
199
|
|
|
this.updateLists(); |
200
|
|
|
}; |
201
|
|
|
|
202
|
|
|
|
203
|
|
|
Line.prototype.updateLists = function () { |
204
|
|
|
'use strict'; |
205
|
|
|
|
206
|
|
|
var source = $("#dynline" + this.m_id + " .source"), |
207
|
|
|
target = $("#dynline" + this.m_id + " .target"), |
208
|
|
|
i, |
209
|
|
|
m; |
210
|
|
|
|
211
|
|
|
source.empty(); |
212
|
|
|
target.empty(); |
213
|
|
|
|
214
|
|
|
source.append('<option value="-1">?</option>'); |
215
|
|
|
target.append('<option value="-1">?</option>'); |
216
|
|
|
|
217
|
|
|
for (i = 0; i < Markers.getSize(); i = i + 1) { |
218
|
|
|
m = Markers.getById(i); |
219
|
|
|
if (!m.isFree()) { |
220
|
|
|
source.append('<option value="' + i + '">' + m.getAlpha() + '</option>'); |
221
|
|
|
target.append('<option value="' + i + '">' + m.getAlpha() + '</option>'); |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
$("#dynline" + this.m_id + " .source > option[value=" + this.m_source + "]").attr("selected", "selected"); |
226
|
|
|
$("#dynline" + this.m_id + " .target > option[value=" + this.m_target + "]").attr("selected", "selected"); |
227
|
|
|
|
228
|
|
|
this.update(); |
229
|
|
|
}; |
230
|
|
|
|
231
|
|
|
|
232
|
|
|
Line.prototype.distance = function () { |
233
|
|
|
'use strict'; |
234
|
|
|
|
235
|
|
|
return this.m_distance; |
236
|
|
|
}; |
237
|
|
|
|